package com.snatch.snatchmgr.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.snatch.common.constant.SnatchConstant;
import com.snatch.snatchmgr.constant.SYSConstant;
import com.snatch.snatchmgr.service.SnatchService;
import com.snatch.snatchmgr.vo.SnatchGame;


@Controller
@RequestMapping("/snatch")
public class SnatchItemController {
	
	@Autowired
	SnatchService snatchService;
	@RequestMapping("start")
	public String startSnatch(String webCode,String gameCode,String itemName,String itemType, final RedirectAttributes redirectAttributes){
		if(webCode!=null && gameCode!=null){
			snatchService.startSnatch(webCode, gameCode,itemName,itemType);
		}
		redirectAttributes.addAttribute("webCode", webCode);
		redirectAttributes.addAttribute("gameCode", gameCode);
		return "redirect:/snatch/findItem";
	}
	
	@RequestMapping("findItem")
	public String findItem(Model model,String webCode,String gameCode){
		if(null == webCode){
			webCode = SnatchConstant.THIRD_SYSTEM_HG_VALUE;
		}
		if(null == gameCode){
			gameCode = SnatchConstant.FOOTBALL;
		}
		SnatchGame snatchGame  = snatchService.findItem(webCode, gameCode);
		List<SnatchGame> snatchGames = snatchService.findGames(webCode);
		model.addAttribute("snatchGames",snatchGames);
		model.addAttribute("snatchGame", snatchGame);
		model.addAttribute("webCode", webCode);
		model.addAttribute("gameCode", gameCode);
		return "snatch/snatchItems";
	}
	
	
	
	
	
}
